package wsz.edu.ad.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wsz.edu.dto.PromotionAdDTO;
import wsz.edu.dto.PromotionSpaceDTO;
import wsz.edu.remote.AdRemoteService;
import wsz.edu.response.ResponseDTO;

import java.util.List;

/**
 * @author wsz
 * @date 2022/4/25 14:00
 **/
@RestController
@RequestMapping("/ad")
public class AdController {
    /**
     * 调用远程服务的接口service
     */
    @Autowired
    private AdRemoteService adRemoteService;


    /*********************************  广告位  ******************************/

    @GetMapping("/space/getAllSpaces")
    public ResponseDTO getAllSpaces() {
        List<PromotionSpaceDTO> allSpaces = adRemoteService.getAllSpaces();
        return ResponseDTO.success(allSpaces);
    }

    @PostMapping("/space/saveOrUpdateSpace")
    public ResponseDTO saveOrUpdateSpace(@RequestBody PromotionSpaceDTO spaceDTO) {
        return adRemoteService.saveOrUpdateSpace(spaceDTO);
    }

    @GetMapping("/space/getSpaceById")
    public ResponseDTO getSpaceById(@RequestParam("id") Integer id) {
        return adRemoteService.getSpaceById(id);
    }

    /*********************************  广告  ******************************/

    @GetMapping("/getAllAds")
    public ResponseDTO getAllAds() {
        return adRemoteService.getAllAds();
    }

    @PostMapping("/saveOrUpdateAd")
    public ResponseDTO saveOrUpdateAd(@RequestBody PromotionAdDTO adDTO) {
        return adRemoteService.saveOrUpdateAd(adDTO);
    }

    @GetMapping("/getAdById")
    public ResponseDTO getAdById(@RequestParam("id") Integer id) {
        return adRemoteService.getAdById(id);
    }
}
